﻿using CommonExtensions.ExpressionExtensions.OfFunc;
using System;
using System.Linq.Expressions;
using Xunit;

namespace CommonExtensions.Tests
{
    public class ExpressionExtensionsTest
    {
        [Fact]
        public void GetPropertyNameShouldThrowIfNotAMemberAccessExpression()
        {
            Expression<Func<TestObject, object>> expression = t => t.TestMethod();
            Assert.Throws<ArgumentException>(() => expression.GetPropertyName());
        }

        [Fact]
        public void GetPropertyNameShouldReturnPropertyName()
        {
            Expression<Func<TestObject, object>> expression = t => t.TestProperty;
            Assert.Equal("TestProperty", expression.GetPropertyName());
        }

        private class TestObject
        {
            public object TestProperty { get; set; }

            public object TestMethod()
            {
                return new {};
            }
        }
    }
}
